//
//  TGMModel2TableViewAdapter.h
//  TravelGuideMdd
//
//  Created by Song Xiaofeng on 13-9-11.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TGMModel2ScrollViewAdapter.h"
#import "TGMBaseModel.h"
#import "TGMTableMoreCell.h"
#import "TGMTableEmptyCell.h"
#import "TGMBaseTableCell.h"

@class TGMModel2TableViewAdapter;
@protocol TGMMode2TableViewAdapterDelegate <TGMModel2ScrollViewAdapterDelegate>

@optional
- (BOOL)adapter:(TGMModel2TableViewAdapter*)adapter tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath;

- (UIEdgeInsets)adapter:(TGMModel2TableViewAdapter*)adapter tableViewLayoutContentInset:(UITableView *)tableview;

- (void)hasCacheWithAdapter:(TGMModel2TableViewAdapter*)adapter;

- (void)adapter:(TGMModel2TableViewAdapter*)adapter emptyCellClickWithUrl:(NSString *)url;
@end


@protocol TGMMode2TableViewScrollDelegate <NSObject>
- (void)model2TableViewDidScroll:(UIScrollView*)scrollView;
- (void)model2TableViewWillBeginDragging:(UIScrollView *)scrollView;
- (void)model2TableViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)model2TableViewWillBeginDecelerating:(UIScrollView *)scrollView;
- (void)model2TableViewDidEndDecelerating:(UIScrollView *)scrollView;
- (void)model2TableViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
@end

@interface TGMModel2TableViewAdapter : TGMModel2ScrollViewAdapter<TGMMode2TableViewScrollDelegate>
{
    @protected
    TGMTableMoreCell *_getMoreCell;
    TGMTableEmptyCell *_emptyCell;
    TGMBaseTableCell *_noMoreDataCell;
    
    id _listData;
    
    BOOL _hasBinded;
}
@property(nonatomic, weak, readonly)UITableView   *tableView;
@property(nonatomic, strong, readonly)TGMBaseModel     *model;

@property(nonatomic, weak)id <TGMMode2TableViewAdapterDelegate> delegate;


@property(nonatomic, strong)id listData;
@property(nonatomic, readonly)BOOL hasBinded;

@property(nonatomic, strong)UIImage *emptyContentImage;//内容为空时候的图片，子类可以覆盖getter方法
@property(nonatomic, strong)NSString *emptyContentText;//内容为空时候的文字
@property (nonatomic,assign)BOOL emptyCellReceiveClick;//控制空cell能否点击刷新 default YES
@property(nonatomic,assign)NSInteger emptyCellHeight;//业务需求 空cell在餐厅页面高度要调整为0
@property(nonatomic,copy)NSString * emptyCellUrl;//本地跳转的url  比如提示用户写游记  写餐厅 只有当url>0时 才能显示 否则显示默认提示文案
@property(nonatomic,copy)NSString * emptyCellActionString;//本地跳转的提示的文案  例如 点击写游记
@property(nonatomic,assign)BOOL showErrorViewWhenNotNet;//emptycell 是否显示网络错误的view
@property(nonatomic,copy)void(^emptyCellClickBlock)(void);
@property(nonatomic,copy)void(^emptyCellErrorViewClickRefreshBlock)(void);
@property(nonatomic,copy)void(^emptyCellErrorViewClickOpenSetting)(void);
/**
 *  当前tableview的contentOffset。当刷新还没有完成的时候，返回初始UNKNOWN
 *
 *  @return contentOffset
 */
- (int)markedContentOffsetYOfTableView;

/**
 * @param tableView
 * @param model
 * @param initOffsetY
 */


- (void)bindTableView:(UITableView*)tableview
            withModel:(TGMBaseModel*)model
           actionData:(TGMBaseModelActionData*)data
            atOffsetY:(int)initOffsetY;

- (void)bindTableView:(UITableView*)tableview
            withModel:(TGMBaseModel*)model
           actionData:(TGMBaseModelActionData*)data
            atOffsetY:(int)initOffsetY
           emptyImage:(UIImage*)emptyImage
            emptyText:(NSString*)emptyText;



- (BOOL)shouldModelInitRefresh;//default return YES
- (void)triggerModelInitRefresh;
- (void)requestRefreshWithNonAnimation;
#pragma mark - tableview ui delegate

- (NSInteger)model2UITableView_numberOfSectionsInTableView:(UITableView *)tableView;

- (NSInteger) model2UITableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section;

- (UITableViewCell *)model2UITableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;

- (CGFloat)model2UITableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)model2UITableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)model2UITableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

-(void)model2UITableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

- (UIView *)model2UITableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (CGFloat)model2UITableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (UIView *)model2UITableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
- (CGFloat)model2UITableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

- (NSInteger)model2TableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;

- (CGFloat)model2UITableView_heightForNoMoreDataCell:(UITableView *)tableView;

- (NSArray<NSString *> *)model2SectionIndexTitlesForTableView:(UITableView *)tableView;

- (BOOL)model2UITableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
/**
 * @return
 *   YES - 子类处理了点击
 *   NO  - 子类未处理
 */
- (BOOL)model2UITableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

@end
